package flc.ast.fragment;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.activity.SelVideoActivity;
import flc.ast.databinding.FragmentConversionBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link ConversionFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class ConversionFragment extends BaseNoModelFragment<FragmentConversionBinding> {

    public static String format = "avi";

    @Override
    protected int onCreate() {
        return R.layout.fragment_conversion;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event5Container);

        mDataBinding.rlAvi.setOnClickListener(this);
        mDataBinding.rlMp4.setOnClickListener(this);
        mDataBinding.rlMkv.setOnClickListener(this);
        mDataBinding.rl3gp.setOnClickListener(this);
        mDataBinding.ivEnterEdit.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.rlAvi:
                clearSelection();
                mDataBinding.ivAvi.setImageResource(R.drawable.gs_1);
                mDataBinding.tvAvi.setTextColor(Color.parseColor("#FFFFFF"));
                format = "avi";
                break;
            case R.id.rlMp4:
                clearSelection();
                mDataBinding.ivMp4.setImageResource(R.drawable.gs_1);
                mDataBinding.tvMp4.setTextColor(Color.parseColor("#FFFFFF"));
                format = "mp4";
                break;
            case R.id.rlMkv:
                clearSelection();
                mDataBinding.ivMkv.setImageResource(R.drawable.gs_1);
                mDataBinding.tvMkv.setTextColor(Color.parseColor("#FFFFFF"));
                format = "mkv";
                break;
            case R.id.rl3gp:
                clearSelection();
                mDataBinding.iv3gp.setImageResource(R.drawable.gs_1);
                mDataBinding.tv3gp.setTextColor(Color.parseColor("#FFFFFF"));
                format = "3gp";
                break;
            case R.id.ivEnterEdit://进入编辑
                goSelPermission(5);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void goSelPermission(int type) {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_IMAGE_VIDEO)
                .reqPermissionDesc(getString(R.string.get_storage_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        SelVideoActivity.type = type;
                        startActivity(SelVideoActivity.class);
                    }
                }).request();
    }

    private void clearSelection() {
        mDataBinding.ivAvi.setImageResource(R.drawable.gs_2);
        mDataBinding.tvAvi.setTextColor(Color.parseColor("#1F0B13"));
        mDataBinding.ivMp4.setImageResource(R.drawable.gs_2);
        mDataBinding.tvMp4.setTextColor(Color.parseColor("#1F0B13"));
        mDataBinding.ivMkv.setImageResource(R.drawable.gs_2);
        mDataBinding.tvMkv.setTextColor(Color.parseColor("#1F0B13"));
        mDataBinding.iv3gp.setImageResource(R.drawable.gs_2);
        mDataBinding.tv3gp.setTextColor(Color.parseColor("#1F0B13"));
    }

}